package code.juc.timer.test1;

import lombok.SneakyThrows;

import java.util.Calendar;
import java.util.Date;
import java.util.Timer;
import java.util.concurrent.TimeUnit;

/**
 * 未来执行的任务
 */
public class Test1 {

    @SneakyThrows
    public static void main(String[] args) {
        System.out.println("当前时间为: " + new Date());
        Calendar calendarRef = Calendar.getInstance();
        calendarRef.add(Calendar.SECOND, 10);
        Date runDate = calendarRef.getTime();

        MyTask task = new MyTask();
        Timer timer = new Timer(true);
        timer.schedule(task, runDate);


        TimeUnit.SECONDS.sleep(20);
        System.out.println("Main");
    }
}
